﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class EboxRotate : MonoBehaviour
{
    public Texture2D TargetCursor;
    float rotatSpeed = 3f;
    Quaternion targetAngels;
    public int isClose = 0;
    public int isOpen = 0;
    // Use this for initialization
    void Start () {
        targetAngels= Quaternion.Euler(0,180f,0);
	}
	
	// Update is called once per frame
	void Update () {
        if (isClose == 1)
        {
            targetAngels = Quaternion.Euler(0, 180f, 0);
            //GameObject.Find("FangZhen_script").GetComponent<Fangzhen>().DoorWires.SetActive(false);
            transform.rotation = Quaternion.Slerp(this.transform.rotation, targetAngels, rotatSpeed * Time.deltaTime);

            if (Quaternion.Angle(targetAngels, this.transform.rotation) < 118)
            {
                if (MotoRun.DoorWires.activeSelf==true)
                {
                   MotoRun.DoorWires.SetActive(false);
                }

            }

            if (Quaternion.Angle(targetAngels, this.transform.rotation) < 1)
            {
                this.transform.rotation = targetAngels;
                isClose = 0;
            }
         
        }
        /*隐藏导线动画*/
        if (isOpen == 1)
        {
            targetAngels = Quaternion.Euler(0, 0f, 0);
            
            transform.rotation = Quaternion.Slerp(this.transform.rotation, targetAngels, rotatSpeed * Time.deltaTime);
            if (Quaternion.Angle(targetAngels, this.transform.rotation) < 58)
            {
                if (MotoRun.DoorWires.activeSelf == false)
                {
                    MotoRun.DoorWires.SetActive(true);
                }
                
            }
            if (Quaternion.Angle(targetAngels, this.transform.rotation) < 5)
            {
                this.transform.rotation = targetAngels;
                isOpen = 0;
                GameObject.Find("box_door").AddComponent<EboxClick>();
            }

        }
    }
}
